package com.engine.core.rowMapper;


import com.engine.core.domain.GenTableColumn;
import com.engine.core.util.Utils;

public class MappedType {

    private String label;

    private String column;

    private String format;

    private String typeName;

    private GenTableColumn genTableColumn;

    public MappedType(String typeName,String column,GenTableColumn dbTypeName) {
        this.column = column;
        this.typeName = typeName;
        this.genTableColumn=dbTypeName;
    }

    public MappedType(String typeName,String column, String format) {
        this.column = column;
        this.format = format;
        this.typeName = typeName;
    }

    public MappedType(String typeName, String column, String format, GenTableColumn dbTypeName) {
        this.column = column;
        this.format = format;
        this.typeName = typeName;
        this.genTableColumn=dbTypeName;
    }

    public MappedType(String typeName,String column) {
        this.column = column;
        this.typeName = typeName;
    }

    public MappedType(String column) {
        this.column = column;
    }

    public MappedType() {
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getColumn() {
        return column;
    }

    public void setColumn(String column) {
        this.column = column;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }


    public GenTableColumn getGenTableColumn() {
        return genTableColumn;
    }

    public void setGenTableColumn(GenTableColumn genTableColumn) {
        this.genTableColumn = genTableColumn;
    }

    public Class<?> getTypeClass(){
        Class classz= Utils.stringClassMap.get(typeName);
        if(classz==null){
            try {
                classz=Class.forName("java.lang."+typeName);
            } catch (ClassNotFoundException e) {
            }
            try {
                classz=Class.forName("java.util."+typeName);
            } catch (ClassNotFoundException e) {
            }

            try {
                classz=Class.forName("java.sql."+typeName);
            } catch (ClassNotFoundException e) {
            }
        }
        if(classz==null){
            throw new RuntimeException(String.format("typeName:%s is not support",typeName));
        }
        return classz;

    }
}
